package com.li.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.li.pojo.po.Notice;
import com.li.pojo.po.PageResult;
import com.li.pojo.po.Result;
import com.li.service.NoticeService;

import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/notice")
@AllArgsConstructor
public class NoticeController {
    private final NoticeService noticeService;

    @GetMapping("/pagelist/{status}")
    public PageResult getPage(@RequestParam(defaultValue = "1")Integer pageNum,
                              @RequestParam(defaultValue = "10")Integer pageSize,
                              @PathVariable String status) {
        PageResult pageResult = noticeService.getPage(pageNum,pageSize,status);
        return pageResult;
    }

    /**
     * 获取单个通知
     *
     * @param noticeId 通知id
     * @return 信息
     */
    @GetMapping("/{noticeId}")
    public Result getNoticeId(@PathVariable Long noticeId) {
//        noticeService.getByNoticeId()
        Notice byId = noticeService.getById(noticeId);
        return Result.success(byId);
    }

    /**
     * 获取某个类别
     *
     * @param status 状态
     * @return 类别
     */
    @GetMapping("/list/{status}")
    public Result getStatus(@PathVariable String status) {
        LambdaQueryWrapper<Notice> queryWrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<Notice> eq = queryWrapper.eq(Notice::getStatus, status);
        return Result.success(noticeService.list(queryWrapper));
    }

    @PutMapping("/{noticeId}")
    public Result updateNoticeStatus(@PathVariable Integer noticeId){
        noticeService.updateByNoticeId(noticeId);
        return Result.success();
    }
}
